#ifndef NODO_H
#define NODO_H

#include <sstream>
#include "../persistencia/container.cpp"

template <class Key, class Record>
class TreeRecord : public Serializable {
    public:
        TreeRecord();
        TreeRecord(bool leave);

        bool isLeave();
        void setLeave(bool leave);

        virtual void read(BinaryStream& in);
        virtual void write(BinaryStream& out);
        virtual std::string toString();

        Key getKey();
        void setKey(Key key);

        Record getData();
        void setData(Record record);

        u_int32_t getLeftNode();
        void setLeftNode(u_int32_t leftNode);

        u_int32_t getRightNode();
        void setRightNode(u_int32_t rightNode);

        static void setInLeave(bool inLeave);

    private:       
        bool leave;
        u_int32_t leftNode;
        Key key;
        Record record;
        u_int32_t rightNode; //No se guarda

        static bool inLeave;
};

template<class Key, class Record>
class Node : public Container<Key, TreeRecord<Key, Record> > {
    public:
        Node(u_int32_t blockSize);

        virtual bool add(TreeRecord<Key, Record> record, bool ignoreSize = false);
        virtual void read(BinaryStream& in);
        virtual void write(BinaryStream& out);

        bool isLeave();
        u_int32_t getDescendant(Key key);

        u_int16_t getLevel();
        void setLevel(u_int16_t level);

        u_int32_t getRightNode();
        void setRightNode(u_int32_t rightNode);

        u_int32_t getNodeNumber();
        void setNodeNumber(u_int32_t nodeNumber);

        std::string toString();

    private:
        u_int16_t level; // nivel del nodo
        u_int32_t nodeNumber; //transient
        u_int32_t rightNode;
};

#endif // NODO_H
